import Vue from 'vue'
import App from './App.vue'
import router from './router'

document.title = '赛云'

// 自定义指令
import '@/assets/directives.js'

import '@/assets/css/common.css' //公共样式

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

// 富文本
import VueQuillEditor from 'vue-quill-editor'
// require styles
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(VueQuillEditor);


// Vue.prototype.$url = 'http://192.168.62.63:9988'
Vue.prototype.$url = 'http://report.lvtutech.com/sbr'
// axioss
import axios from 'axios'
Vue.prototype.$axios = axios;
// axios.defaults.baseURL = 'http://192.168.62.63:9988'
axios.defaults.baseURL = 'http://report.lvtutech.com/sbr'

//post请求头
// axios.defaults.headers.post["Content-Type"] =
//   "application/x-www-form-urlencoded;charset=UTF-8";
// const _axios = axios.create();
// //设置超时
axios.defaults.timeout = 10000;

// 请求拦截器
// axios.interceptors.request.use(function (config) {
//     // 在请求头中添加token
//     config.headers.Authorization = `121`
//   // config 是当前请求的相关配置信息对象，可以修改
//   // 当这里 return config之后，才会真正发送请求
//   return config
// }, function (error) {
//   // 请求发送失败
//   return Promise.reject(error)
// })
//响应拦截器
axios.interceptors.response.use(res => {
  let rr = res.data
  //res是响应的结果
  if (rr.code&&rr.code != 200) {
    // 获取失败
    if (rr.msg) ElementUI.Message.error(rr.msg)
    return
  }
  return res
})
  // err => Promise.reject(error));


// 加密与解密 encode decode
let Base64 = require('js-base64').Base64
Vue.prototype.$Base64 = Base64;
import VueCookies from "vue-cookies"
Vue.prototype.$cookies = VueCookies;
router.beforeEach((to, from, next) => {
  let userM = VueCookies.get("user_session")
  if (userM) {
    Vue.prototype.$orgId = JSON.parse(
      Base64.decode(VueCookies.get("user_session"))
    ).id;
    VueCookies.set("user_session", userM, 60 * 60 * 24 * 3);
    if (to.path == '/') { router.replace('/home') }
    else next()
  } else {
    // console.log(to.path, from.path)
    if (to.path == '/' || to.path == '/register') {
      next()
    } else next({ path: "/" })
  }
})
Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
